//
//  TopViewController.swift
//  beegin2
//
//  Created by zsy on 16/3/6.
//  Copyright © 2016年 kszz. All rights reserved.
//

import UIKit

class TopViewController: UIViewController ,UITableViewDelegate,UITableViewDataSource, FSCalendarDataSource, FSCalendarDelegate{

    @IBOutlet weak var circularProgressView: THCircularProgressView!
    @IBOutlet weak var tipTableView: UITableView!
    
    @IBOutlet weak var dayButton:UIButton!
    
    
    lazy var stagesCalendar:StageCalendarView = {
        
        var arry:NSArray = NSBundle.mainBundle().loadNibNamed("StageCalendarView", owner: self, options: nil)
        
        if let calendar = arry[0] as? StageCalendarView{
            
            calendar.frame = CGRect(x: 0, y: 44, width: self.view.frame.width, height: 220)
            
            self.view.addSubview(calendar)
            calendar.hidden = true
            calendar.calendarView.delegate = self
            calendar.calendarView.dataSource = self
            calendar.calendarView.autoAdjustTitleSize = true
            
            FSCalendar.appearance().setHeaderDateFormat("yyyy/MM")
            FSCalendar.appearance().minDissolvedAlpha = 1.0
            
            return calendar
        }
        return StageCalendarView(frame: CGRect(x: 0, y: 64, width: self.view.frame.width, height: 300))
    }()
    
    @IBOutlet weak var tipTableViewCell: UITableViewCell!
    
    override func viewDidLoad() {
        super.viewDidLoad()

         tipTableView.registerNib(UINib(nibName: "TipViewCell", bundle: nil), forCellReuseIdentifier: "tipViewCell")
        // Do any additional setup after loading the view.
        dayButton.addTarget(self, action: #selector(TopViewController.dataPickClick(_:)), forControlEvents: .TouchUpInside)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    
    
    @IBAction func dataPickClick(sender:AnyObject){

            self.stagesCalendar.hidden = !self.stagesCalendar.hidden
    }
    
    // MARK: - UITableViewDelegate
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){
        
        if indexPath.section == 0 && indexPath.row == 0{
            
            //self.performSegueWithIdentifier("showMilkBrandSegue", sender: self)
        }
        
        tableView.deselectRowAtIndexPath(indexPath, animated: true)
    }
    
    func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        
        return nil
    }
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        return 1
    }
    
    func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        
        return 0
    }
    func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        
        let identifier = "tipViewCell"
        let cell = tableView.dequeueReusableCellWithIdentifier(identifier , forIndexPath: indexPath)
        cell.layer.cornerRadius = 7

        return cell
    }



    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
